package com.zhiyou.controller;

import com.zhiyou.util.DBUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author sanshi
 * @desc
 * @create 2021-09-15 20:07
 */
@WebServlet("/DoAddNews")
public class DoAddNews extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //栏目id
        String selectColumnId = req.getParameter("selectColumn");
        //标题
        String textTitle = req.getParameter("textTitle");
        //主题
        String textDesc = req.getParameter("textDesc");
        Object[] params = {selectColumnId,textTitle,textDesc};
        String sql = "insert into news (chnl_code,title,detail) values(?,?,?)";
        int i = new DBUtil().updateInfo(sql, params);
        if (i==0){
            resp.sendRedirect("error.jsp");
        }else {
            req.getSession().setAttribute("addNews","success");
            resp.sendRedirect("/page/NewsManagement.jsp");
        }

    }
}
